import { createRouter, createWebHashHistory } from "vue-router"


const routes = [
  {
    path: '/',
    component: () => import('../pages/panel/index.vue'),
    children: [
      {
        path: '/user/:id',
        component: () => import('../pages/panel/profile.vue')
      },
      {
        path: 'projects',
        component: () => import('../pages/panel/projects.vue'),
        meta: {
          name: '项目'
        }
      },
      {
        path: 'projects/create',
        component: () => import('../pages/panel/project/create.vue'),
        meta: {
          name: '创建项目'
        }
      },
      {
        path: 'projects/:id',
        component: () => import('../pages/panel/project/projectView.vue')
      },
      {
        path: 'projects/edit/:id',
        component: () => import('../pages/panel/project/project.vue')
      },
      {
        path: 'technologies',
        component: () => import('../pages/panel/technology/technologies.vue'),
        meta: {
          name: '技术栈'
        }
      },
      {
        path: 'technologies/create',
        component: () => import('../pages/panel/technology/create.vue'),
        meta: {
          name: '创建技术'
        }
      },
      {
        path: 'technologies/:id',
        component: () => import('../pages/panel/technology/technology.vue')
      },
      {
        path: 'users',
        component: () => import('../pages/panel/user/users.vue'),
        meta: {
          name: '成员'
        }
      },
      {
        path: 'users/create',
        component: () => import('../pages/panel/user/create.vue'),
        meta: {
          name: '添加成员'
        }
      },
      {
        path: 'control',
        component: () => import('../pages/panel/control/control.vue'),
        meta: {
          name: '管理'
        }
      },
      {
        path: 'user/info',
        component: () => import('../pages/panel/userInfo.vue'),
        meta: {
          name: '修改信息'
        }
      },
      {
        path: 'department',
        component: () => import('../pages/department/index.vue'),
        meta: {
          name: '部门'
        }
      },
      {
        path: 'department/:id',
        component: () => import('../pages/department/department.vue'),
        meta: {
          name: '部门'
        }
      },
      {
        path: 'department/edit/:id',
        component: () => import('../pages/department/departmentControl.vue'),
      },
      {
        path: 'info',
        component: () => import('../pages/info/index.vue'),
        meta: {
          name: '消息',
        },
        redirect: '/info/mailr',
        children: [
          {
            path: '/info/mailr',
            component: () => import('../pages/info/mail/mailRecipient.vue'),
          },
          {
            path: '/info/mails',
            component: () => import('../pages/info/mail/mailSender.vue'),
          },
          {
            path: '/info/mailr/:id',
            component: () => import('../pages/info/mail/mail.vue'),
          },
          {
            path: '/info/mails/:id',
            component: () => import('../pages/info/mail/ownmail.vue'),
          },
          {
            path: '/info/mail/create',
            component: () => import('../pages/info/mail/create.vue'),
          },
          {
            path: '/info/notice',
            component: () => import('../pages/info/notice/index.vue'),
          },
          {
            path: '/info/notice/:id',
            component: () => import('../pages/info/notice/notice.vue'),
          },
          {
            path: '/info/notice/create',
            component: () => import('../pages/info/notice/create.vue'),
          },
        ]
      },
    ]
  },
  {
    path: '/login',
    component: () => import('../pages/login/index.vue'),
    meta: {
      name: '登录页面'
    }
  },
  {
    path: '/empty',
    component: () => import('../pages/empty/index.vue')
  },
]


const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  if (to.meta.name) {
    document.title = to.meta.name
  }
  next()
})

export default router
